debugDict = {
'ModSchema': ['QAM','QAM','PSK','PSK'],
'pulseShaping': ['rrc','square','rrc','square'],
'txAmp': [40,40,40,40],
'rxAmp': [20,20,20,20],
'BER': [0.495,0.59,0.45,0.5545]
}
def plotBaseBandData(data,symbol,rxSymbol=[]):
colors = np.zeros(len(data))
if len(rxSymbol)>0:
figure, axis = ploot.subplots(1, 2)
for i in range(len(rxSymbol)):
colors[i] = rxSymbol[i]/4
axis[1].scatter(data.real,data.imag,c=colors)
for i in range(len(symbol)):
colors[i] = symbol[i]/4
axis[0].scatter(data.real,data.imag,c=colors)
ploot.show()
else:
for i in range(len(symbol)):
colors[i] = symbol[i]/4
ploot.scatter(data.real,data.imag,c=colors)
def Convolve(data1,data2):
ans = np.zeros(len(data1),dtype=type(data1[0]))
for i in range(0,len(data1)):
for j in range(0,len(data2)):
if i-j >=0:
ans[i] = ans[i] + data1[i-j]*data2[j]
return ans
def getSNRvsBER(snrMin,snrMax,step):
snr = np.linspace(snrMin,snrMax,step)
ber = np.zeros(len(snr))
for i in range(len(snr)):
rxAmpDB = 20
pbRx = np.convolve(pb,ir,mode = 'same')
pbRx = comm.awgn(pbRx,snr[i])
pbRx = pbRx * (10**(rxAmpDB//20))
bbRx = comm.downconvert(pbRx, int(samplingRate/symbolRate),carrierFreq,samplingRate)
rxSymbols = comm.demodulate(bbRx,psk)
ber[i] = comm.ber(comm.sym2bi(rxSymbols,m),comm.sym2bi(symbols,m))
fig, ax = ploot.subplots(1, 1, figsize=(4, 4), layout='constrained')
ax.set_xlabel('SNR')
ax.set_ylabel('BER')
ax.set_ylim(0,1)
ax.set_xscale('log')
ax.plot(snr,ber,'x',ls='-')
return
def getBeamPattern(dictofDegree):
ptrn = np.zeros((37,2))
for i in range(len(ptrn)):
ptrn[i][0] = -180 + i*10
try:
ptrn[i][1] = dictofDegree[-180 + i*10]
except:
ptrn[i][1] = 0
return ptrn
def plotDiffData(rx_range_min,rx_range_max,samples):
rx_range = np.linspace(rx_range_min,rx_range_max,samples)
for i in rx_range:
env = pm.create_env2d(frequency=27000,tx_depth=40,rx_depth=10,depth=100,rx_range=i,tx_directionality=getBeamPattern({0:20,10:20,20:20,-20:20,-10:20,30:20,-30:20}),bottom_absorption=0.1)
arrivals = pm.compute_arrivals(env)
ir = pm.arrivals_to_impulse_response(arrivals, fs=100000)
pbRx = np.convolve(pb,abs(ir)[0:int(0.1*100000)])
pbRx = pbRx[:len(pb)]
pbRx = comm.awgn(pbRx,20)
pbRx = pbRx * (10**(rxAmpDB//20))
bbRx = comm.downconvert(pbRx, int(samplingRate/symbolRate),carrierFreq,samplingRate)
rxSymbols = comm.demodulate(bbRx,psk)
print("Range: " + str(i))
print(comm.ber(comm.sym2bi(rxSymbols,m),comm.sym2bi(symbols,m)))
plotBaseBandData(bbRx,symbols,rxSymbol=rxSymbols)
import arlpy.uwapm as pm
import arlpy.comms as comm
import arlpy.plot as plt
import arlpy.signal as signal
import numpy as np
from scipy.fft import fft, fftfreq
import matplotlib.pyplot as ploot
import math
import matplotlib.axes as axes
pm.models()
rx_range = 2000
tx_depth = 500
rx_depth = 450
print(np.rad2deg(np.arctan((tx_depth-rx_depth)/rx_range)))
env = pm.create_env2d(frequency=27000,tx_depth=tx_depth,rx_depth=rx_depth,depth=1000,rx_range=rx_range,tx_directionality=getBeamPattern({0:20,10:20,20:20,-20:20,-10:20,30:20,-30:20}),bottom_absorption=0.1)
arrivals = pm.compute_arrivals(env)
ir = pm.arrivals_to_impulse_response(arrivals, fs=100000)
pm.print_env(env)
plt.plot(abs(ir)[0:int(0.1*100000)],fs = 100000)
1.4320961841646465
name : arlpy
bottom_absorption : 0.1
bottom_density : 1600
bottom_roughness : 0
bottom_soundspeed : 1600
depth : 1000
depth_interp : linear
frequency : 27000
max_angle : 80
min_angle : -80
nbeams : 0
rx_depth : 450
rx_range : 2000
soundspeed : 1500
soundspeed_interp : spline
surface : None
surface_interp : linear
tx_depth : 500
tx_directionality : [[-180. 0.]
[-170. 0.]
[-160. 0.]
[-150. 0.]
[-140. 0.]
[-130. 0.]
[-120. 0.]
[-110. 0.]
[-100. 0.]
[ -90. 0.]
[ -80. 0.]
[ -70. 0.]
[ -60. 0.]
[ -50. 0.]
[ -40. 0.]
[ -30. 20.]
[ -20. 20.]
[ -10. 20.]
[ 0. 20.]
[ 10. 20.]
[ 20. 20.]
[ 30. 20.]
[ 40. 0.]
[ 50. 0.]
[ 60. 0.]
[ 70. 0.]
[ 80. 0.]
[ 90. 0.]
[ 100. 0.]
[ 110. 0.]
[ 120. 0.]
[ 130. 0.]
[ 140. 0.]
[ 150. 0.]
[ 160. 0.]
[ 170. 0.]
[ 180. 0.]]
type : 2D
print(len(ir))
# Number of samples in normalized_tone
N = len(abs(ir)[0:int(0.1*100000)])
yf = fft(ir[0:int(0.1*100000)])
xf = fftfreq(N, 1 / 100000)
plt.plot(xf, np.abs(yf))
348763
#data Generation and Config
dataSize = 2000
m = 4
n = 2
samplingRate = 100000
carrierFreq = 27000
bitRate = 80
symbolRate = bitRate//n
txAmpDB = 40
rrcTaps = 6
#data Modulation
data =comm.random_data(dataSize, 2)
symbols = comm.bi2sym(data,m)
psk = comm.qam(m)
bb1 = comm.modulate(symbols,psk)
pb = comm.upconvert(bb1, int(samplingRate/symbolRate),carrierFreq,samplingRate)
#Power Amplification
pb = pb * (10**(txAmpDB//20))
#Plotting
time = signal.time(pb,100000)
plt.plot(time,pb)
rxAmpDB = 0
#Received Signal
pbRx = np.convolve(pb,abs(ir)[0:int(0.1*100000)])
pbRx = pbRx[:len(pb)]
pbRx = comm.awgn(pbRx,20)
#Power Amplification
pbRx = pbRx * (10**(rxAmpDB//20))
#plotting
time = signal.time(pbRx,100000)
plt.plot(time,pbRx)
#Demodulating Signal
bbRx = comm.downconvert(pbRx, int(samplingRate/symbolRate),carrierFreq,samplingRate)
rxSymbols = comm.demodulate(bbRx,psk)
comm.ber(comm.sym2bi(rxSymbols,m),comm.sym2bi(symbols,m))
0.0
plotBaseBandData(bb1,symbols)
plotBaseBandData(bbRx,symbols)
plotDiffData(10,300,20)
Range: 10.0 0.093
Range: 25.263157894736842 0.2195
Range: 40.526315789473685 0.0
Range: 55.78947368421053 0.0
Range: 71.05263157894737 0.0
Range: 86.31578947368422 0.0
Range: 101.57894736842105 1.0
Range: 116.84210526315789 0.4035
Range: 132.10526315789474 0.4325
Range: 147.3684210526316 0.0235
Range: 162.63157894736844 0.12
Range: 177.89473684210526 0.417
Range: 193.1578947368421 0.0
Range: 208.42105263157896 0.0005
Range: 223.68421052631578 0.0
Range: 238.94736842105263 0.3545
Range: 254.21052631578948 0.0
Range: 269.4736842105263 0.0
Range: 284.7368421052632 0.0
Range: 300.0 0.458
172,253 # ungroup
1065 # Exact
1106 # Shift
984,1025,1147,1187 # Scatter
(172, 253, 984, 1025, 1065, 1106, 1147, 1187)
arr = [10, 25, 101,300]
for i in arr:
env = pm.create_env2d(frequency=27000,tx_depth=40,rx_depth=10,depth=100,rx_range=i,tx_directionality=getBeamPattern({0:20,10:20,20:20,-20:20,-10:20,30:20,-30:20}),bottom_absorption=0.1)
arrivals = pm.compute_arrivals(env)
ir = pm.arrivals_to_impulse_response(arrivals, fs=100000)
plt.plot(abs(ir)[0:int(0.1*100000)],fs = 100000)
arr = [1350,1228,1228.3673469387757,1390,1431,1472,1512,1553]
for i in arr:
env = pm.create_env2d(frequency=27000,tx_depth=40,rx_depth=10,depth=100,rx_range=i,tx_directionality=getBeamPattern({0:20,10:20,20:20,-20:20,-10:20,30:20,-30:20}),bottom_absorption=0.1)
arrivals = pm.compute_arrivals(env)
ir = pm.arrivals_to_impulse_response(arrivals, fs=100000)
plt.plot(abs(ir)[0:int(0.1*100000)],fs = 100000)
1/80
0.0125
1/40
0.025
#Getting Equalizer coefficients
trainSymbols = [0,1,2,3,2,1,0,2,3,1,2,0,3,1,3,0,0,1,2,3,2,1,0,2,3,1,2,0,3,1,3,0]
psk = comm.psk(4)
bb1 = comm.modulate(trainSymbols,psk)
#Upsampling
bb1 = comm.upconvert(bb1, int(samplingRate/symbolRate),0,samplingRate)
#Power Amplification
bb1 = bb1 * (10**(txAmpDB//20))
#Channel Modelling
bbChn = Convolve(bb1,ir)
#modulating
pbChn = comm.upconvert(bbChn,1,carrierFreq,samplingRate)
pbChn = comm.awgn(pbChn,20)
pb = comm.upconvert(bb1,1,carrierFreq,samplingRate)
#Plotting
time = signal.time(pbChn,samplingRate)
plt.plot(time,pbChn)
time = signal.time(pb,samplingRate)
plt.plot(time,pb)
--------------------------------------------------------------------------- KeyboardInterrupt Traceback (most recent call last) Cell In[18], line 12 9 bb1 = bb1 * (10**(txAmpDB//20)) 11 #Channel Modelling ---> 12 bbChn = Convolve(bb1,ir) 13 #modulating 14 pbChn = comm.upconvert(bbChn,1,carrierFreq,samplingRate) Cell In[2], line 10, in Convolve(data1, data2) 8 for i in range(0,len(data1)): 9 for j in range(0,len(data2)): ---> 10 if i-j >=0: 11 ans[i] = ans[i] + data1[i-j]*data2[j] 12 return ans KeyboardInterrupt:
#Demodulating Signal
bbRx = comm.downconvert(pbChn, int(samplingRate/symbolRate),carrierFreq,samplingRate)
bbTrueRx = comm.downconvert(pb, int(samplingRate/symbolRate),carrierFreq,samplingRate)
rxSymbols = comm.demodulate(bbTrueRx,psk)
def getEqCoeff(bbhat,bb,ntap,stepfactor=0.01,convergance=0.001):
bbRxReal = bbhat.real
bbRxImag = bbhat.imag
bbRxTrueReal = bb.real
bbRxTrueImag = bb.imag
eqCoeffReal = np.zeros(len(bbRxReal))
eqCoeffImag = np.zeros(len(bbRxImag))
while()
ir1 = np.zeros(100000,dtype=type(ir[0]))
ir1[0] =complex(1,1)
ir1[50000] = complex(0.01,0.05)
ir1[10000] = complex(0.2,0.05)
ir1[15000] = complex(0.01,0.05)
ir1[7000] = complex(0.3,0.5)
ir1[60000] = complex(0.01,0.05)
ir1[40000] = complex(1,1)
print(len(ir1))
# Number of samples in normalized_tone
N = len(ir1)
yf = fft(ir1)
xf = fftfreq(N, 1 / 100000)
plt.plot(xf, np.abs(yf))
100000
plt.plot(abs(ir1),fs = 100000)
x = complex(1,1)
x
(1+1j)
type(x)
complex
1/40
0.025
len(beampattern[0])
2
x = {0:20
20
plt.plot(abs(ir),fs = 100000)
plt.plot(abs(ir)[0:10000],fs = 100000)
abs(ir)
[4.92515005e-02 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 2.02418723e-05]
k = abs(ir)[0:5000]
for i in range(5000):
if k[i] != abs(ir)[i]:
print(i)
plt.plot(k,fs = 100000)
!jupyter nbconvert --to html equalizer.ipynb
[NbConvertApp] Converting notebook equalizer.ipynb to html [NbConvertApp] Writing 12856321 bytes to equalizer.html